<?php
class HotkeyService extends BaseDbService
{
	public function __construct(){
		$this->dao		= new HotkeyDao();
	}
	
	public function get($id)
	{
		return $this->dao->get($id);
	}
	
	public function add($data)
	{
		if(!array_key_exists('created', $data))
		{
			$data['created']	= date('Y-m-d H:i:s');
		}
		if(!array_key_exists('first_char',$data))
		{
			$tmp				= C('PinYin')->toPinyin($data['name']);
			$data['first_char']	= $tmp[0];
		}
		$result = $this->dao->add($data);
		return $result;
	}
	
	public function del($id)
	{
		$result	= $this->dao->del($id);
		return $result;
	}
	
	public function update($id,$data)
	{
		return $this->dao->update($id,$data);
	}
	
	public function getListByCategoryId($cid)
	{
		if($cid>0)
		{
			$condition['where']['expression'] 	= 'category_id = '.$cid;
		}
		$condition['orderby'] 				= 'orderby DESC';
		$list		= $this->dao->fetchRows($condition);
		return $list;
	}
	
	public function getByNameAndCategoryId($name,$cid)
	{
		$condition['expression'] 		= 'category_id = '.$cid.' AND name=:name';
		$condition['value']['name'] 	= $name;
		return $this->fetch($condition);
	}
}
?>